/**
 * @Project : ProgrammingExercises
 * @Package : Leetcode
 * @File : Q0206.java
 * @Author : WangRuoyu
 * @Date 2022/12/26 18:14
 */

package leetcode;

import util.LinkList;
import util.ListNode;

public class Q0206 {
    public ListNode reverseList(ListNode head) {

        ListNode p = null;

        while (head != null) {
            ListNode s = head.next;
            head.next = p;
            p = head;
            head = s;
        }

        return p;
    }

    public static void main(String[] args) {
        Q0206 sl = new Q0206();
        ListNode head = LinkList.createList(new int[]{3, 2, 0, 4});
        ListNode p = sl.reverseList(head);
        LinkList.printList(p);
    }
}